package com.huaweicloud.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huaweicloud.commons.pojo.User;
import com.huaweicloud.persistent.repository.UserRepository;
import com.huaweicloud.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * user service接口
 */
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserRepository userRepository;

    public boolean save(User user) {
        return userRepository.save(user);
    }

    public boolean update(User user) {
        //创建查询条件构造器
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id", user.getId());
        return userRepository.update(user, queryWrapper);
    }

    @Override
    public User findUserById(String userId) {
        return userRepository.getById(userId);
    }

    public User findByMobile(String mobile) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("mobile", mobile);
        return userRepository.getOne(queryWrapper);
    }
}
